package com.example.yl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.yb.entity.Iyqww_yb_wbssb_ssb;
import com.example.yl.entity.Iyqww_YL_1w1m;
import com.example.yl.entity.Iyqww_YL_1w1mtb;
import com.example.yl.entity.Iyqww_YL_ssbxt;
import com.example.yl.entity.Iyqww_YL_ssbxtVo;
import com.example.yl.service.YLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

/**
 * @author
 * @createtime 2021-08-13 11:16
 * @description
 */
@RestController
@RequestMapping("/yl")
public class YLContorller {

    @Autowired
    private YLService ylService;


    /**
     * transferredList 已办结
     *
     * @param pagenum
     * @param pageSize
     * @param foreignId
     * @return
     */
    @RequestMapping("/transferredList")
    public Page<Iyqww_YL_ssbxtVo> itemList(@RequestParam(defaultValue="1")Integer pagenum,
                                           @RequestParam(defaultValue="5")Integer pageSize,
                                           @RequestParam String foreignId){

        Page<Iyqww_YL_ssbxtVo> page = new Page<>(pagenum, pageSize);
        Page<Iyqww_YL_ssbxtVo> pageList = page.setRecords(ylService.queryAllSsbVo(page ,foreignId));
        System.out.println(page);


        System.out.println("============================");
        pageList.hasNext();
        System.out.println("是否有下一页:"+pageList.hasNext());
        System.out.println("当前页:"+pageList.getCurrent());
        System.out.println("总数："+pageList.getTotal());
        System.out.println("getPages():"+pageList.getPages());
        System.out.println("getOrders():"+pageList.getOrders());
        System.out.println("getSize():"+pageList.getSize());

        return pageList;
    }


    /**
     * ntransferredList 未办结
     *
     * @param pagenum
     * @param pageSize
     * @param foreignId
     * @return
     */
    @RequestMapping("/ntransferredList")
    public Page<Iyqww_YL_ssbxtVo> itemList1(@RequestParam(defaultValue="1")Integer pagenum,
                                           @RequestParam(defaultValue="5")Integer pageSize,
                                           @RequestParam String foreignId){

        Page<Iyqww_YL_ssbxtVo> page = new Page<>(pagenum, pageSize);
        Page<Iyqww_YL_ssbxtVo> pageList = page.setRecords(ylService.queryAllSsbVo1(page ,foreignId));
        System.out.println(page);


        return pageList;
    }

    /**
     * 查询 填报表中的所需的基本数据
     *
     * @return
     */
    @RequestMapping("/findEssential")
    @ResponseBody
    public ArrayList<Map<String, Object>> findEssential() {
        ArrayList<Map<String, Object>> list = ylService.findEssential();
        return list;
    }



    /**
     * 根据地址设置唯一标识值
     *
     * @return
     */
    @RequestMapping("/address")
    public ArrayList<Iyqww_YL_1w1mtb> findAddress() {
        ArrayList<Iyqww_YL_1w1mtb> adds = ylService.findAddress();

        String str;
        String address;
        Iyqww_YL_1w1mtb tb = new Iyqww_YL_1w1mtb();
        int demo = 100000;
        for (int i = 0; i < adds.size(); i++) {
            demo += 1;
            str = "yl" + demo;
            address = adds.get(i).getAddress();
            //根据地址给唯一标识赋值
            ylService.addForeignId(str, address);
        }

        System.out.println(adds);
        return adds;
    }


    /**
     * 随手报表同步一物一码填报表中的唯一标识
     *
     * @return
     */
    @RequestMapping("/update")
    public ArrayList<Iyqww_YL_ssbxt> findAddress1() {
        ArrayList<Iyqww_YL_ssbxt> adds = ylService.findAddress1();
        ArrayList<Iyqww_YL_1w1mtb> adds_tb = ylService.findAddress();
        System.out.println(adds_tb);
        String address;//address
        String foreignId;

        for (int i = 0; i < adds.size(); i++) {
            for (int j = 0; j < adds_tb.size(); j++) {

                //判断随手报中的地址是否与一物一码填报中的地址相同
                if (adds.get(i).getAddress().equals(adds_tb.get(j).getAddress())) {
                    address = adds.get(i).getAddress();
                    foreignId = adds_tb.get(j).getForeignId();
                    //System.out.println(address);
                    //System.out.println(foreignId);
                    ylService.addForeignId1(foreignId, address);
                }
            }
        }

        return null;

    }


    /**
     * 一物一码表同步一物一码填报表中的唯一标识
     *
     * @return
     */
    @RequestMapping("/update2")
    public ArrayList<Iyqww_YL_1w1m> findAddress2() {
        ArrayList<Iyqww_YL_1w1m> adds = ylService.findAddress2();

        ArrayList<Iyqww_YL_1w1mtb> adds_tb = ylService.findAddress();
        System.out.println(adds_tb);

        String address;//address
        String foreignId_val;

        for (int i = 0; i < adds.size(); i++) {
            for (int j = 0; j < adds_tb.size(); j++) {

                if (adds.get(i).getAddress().equals(adds_tb.get(j).getAddress())) {
                    address = adds.get(i).getAddress();
                    foreignId_val = adds_tb.get(j).getForeignId();
                    //System.out.println(address);
                    //System.out.println(foreignId);
                    ylService.addForeignId_val(foreignId_val, address);
                }
            }
        }
        return null;
    }




}
